//要求时间复杂度O(n)。空间复杂度O(1)（不能用splice）
function exchang(nums) {
    let i = 0, j = nums.length - 1
    while (i < j) {
        if (nums[i] % 2 === 1) i++
        if (nums[j] % 2 === 0) j--
        if (nums[i] % 2 === 0 && nums[j] % 2 === 1) {
            [nums[i], nums[j]] = [nums[j], nums[i]]
            i++
            j--
        }
    }
    return nums
}

const arr = [1,2,3,4,5,6,7]
console.log(exchang(arr))